#ifndef INCLUDE_SYNTAX_H
#define INCLUDE_SYNTAX_H

#define MAXLEN 16384

// 算符优先分析
enum operator { Plus, Minus, Mult, Div, Rem, LPar, RPar, UnPlus, UnMinus, Number, Boundary };
enum operator operators[MAXLEN];
int top_opt;
int numbers[MAXLEN];
int registers[MAXLEN];
int top_num;

/* 优先关系表
    0 : = 
    1 : < 
    2 : >
    3 : error */
static const int priority[11][11] = {
    {2, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2},  // '+'
    {2, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2},  // '-'
    {2, 2, 2, 2, 2, 1, 2, 1, 1, 1, 2},  // '*'
    {2, 2, 2, 2, 2, 1, 2, 1, 1, 1, 2},  // '\'
    {2, 2, 2, 2, 2, 1, 2, 1, 1, 1, 2},  // '%'
    {1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 3},  // '('
    {2, 2, 2, 2, 2, 3, 2, 3, 3, 3, 2},  // ')'
    {2, 2, 2, 2, 2, 1, 2, 1, 1, 1, 2},  // '\+'
    {2, 2, 2, 2, 2, 1, 2, 1, 1, 1, 2},  // '\-'
    {2, 2, 2, 2, 2, 3, 2, 3, 3, 3, 2},  // 'i'
    {1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 3},  // '#'
};
int num_register;

void syntaxAnalysis(char *file_input, char *file_output);

// 语法相关
int isFuncDefBegin(char str[]);
void analyseFuncDef(FILE *fp_in, FILE *fp_out);
void analyseStmt(FILE *fp_in, FILE *fp_out);
void analyseBlock(FILE *fp_in, FILE *fp_out);
void analyseExp(FILE *fp_in, FILE *fp_out);

// 算符相关
enum operator judgeOpt(char str[], enum operator pre);
void specify(FILE *fp_out);
void printLLVM(FILE *fp_out, char *str, int a, int b);

#endif